//
//	_MiscMergeIfCommand.m -- "if" merge command implementation
//		Written by Don Yacktman Copyright (c) 1995 by Don Yacktman.
//				Version 1.0.  All rights reserved.
//		This notice may not be removed from this source code.
//
//	This object is included in the MiscKit by permission from the author
//	and its use is governed by the MiscKit license, found in the file
//	"LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
//	for a list of all applicable permissions and restrictions.
//	


#import <misckit/miscmerge.h>
#import "_MiscMergeIfCommand.h"

@implementation _MiscMergeIfCommand

static MiscString *myKey = nil;

- parseFromString:(MiscString *)aString
{
	if (!myKey) {
		myKey = [MiscString new];
		[myKey setStringValue:"if"];
	}
	[self eatKeyWord:myKey from:aString isOptional:NO];
	value1 = [self getArgumentStringFrom:aString toEnd:NO];
	operator = [self getConditionalFrom:aString];
	// if none, then we just expect value1 to be a single field
	// and the condition will evaluate true if it is non-empty.
	// (Or, it may be a keyword that always evals true or false...)
	if (operator != MISC_MCO_NONE) {
		value2 = [self getArgumentStringFrom:aString toEnd:YES];
	}
	return self;
}

- executeForMerge:(MiscMergeEngine *)aMerger
{ // The MiscIfStack object has all the if/then/else logic in it.
	[[aMerger ifStack]
		startIf:[[self class] evaluateConditionWith:aMerger for:self]];
	return self;
}

// MiscMergeCondCallback protocol
- value1 { return value1; }
- value2 { return value2; }
- (MISC_Merge_Cond_Op)operator { return operator; }

@end
